package com.novanok.campaigntweets;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;

import twitter4j.auth.RequestToken;

public class LoginActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
    }

    public void logIn(View view) {
        new TwitterAuthenticateTask().execute();
    }

    class TwitterAuthenticateTask extends AsyncTask<String, String, RequestToken> {

        @Override
        protected void onPostExecute(RequestToken requestToken) {
            WebView browser = (WebView) findViewById(R.id.browser);
            browser.setVisibility(View.VISIBLE);
            browser.loadUrl(requestToken.getAuthenticationURL());
        }

        @Override
        protected RequestToken doInBackground(String... params) {
            return TwitterUtil.getInstance().getRequestToken();
        }
    }
}